home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 2 code / Speed Development / UGraph.cp < prev    next >
Encoding:
Text File  |  1990-03-07  |  2.8 KB  |  123 lines  |  [TEXT/MWII]

  1. // Copyright © 1989-1990 by Apple Computer, Inc.  All rights reserved. 
  2.  
  3.  
  4. #ifndef __UGRAPH__
  5. #include "UGraph.h"
  6. #endif
  7.  
  8. //--------------------------------------------------------------------------------------------------
  9. #pragma segment AOpen
  10.  
  11. pascal void 
  12. TGraph::IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams)
  13. {
  14.     GraphStructPtr aGraphStructPtr;
  15.     Rect    aRect;
  16.     
  17.     inherited::IRes(itsDocument, itsSuperView, itsParams);
  18.     aGraphStructPtr = DoGraphInit(kBar);
  19.     fData = aGraphStructPtr;
  20.     aRect = gZeroRect;
  21.     if (Focus())
  22.         GetQDExtent(&aRect);
  23.     SetGraphRect(aRect);
  24. }
  25.  
  26. //--------------------------------------------------------------------------------------------------
  27. #pragma segment AOpen
  28.  
  29. pascal void 
  30. TGraph::SetGraphRect(Rect graphRect)
  31. {
  32.     DoGraphSetGraphRect(graphRect.top, graphRect.left, graphRect.bottom, graphRect.right, fData);
  33. }
  34.  
  35. //--------------------------------------------------------------------------------------------------
  36. #pragma segment ARes
  37.  
  38. pascal void 
  39. TGraph::SetPoint( short which, long value )
  40. {
  41.     DoGraphSetPoint(which, value, fData);
  42. }
  43.  
  44. //--------------------------------------------------------------------------------------------------
  45. #pragma segment ARes
  46.  
  47. pascal short 
  48. TGraph::GetNumPoints()
  49. {
  50.     return DoGraphGetNumPoints(fData);
  51. }
  52.  
  53. //--------------------------------------------------------------------------------------------------
  54. #pragma segment ARes
  55.  
  56. pascal void 
  57. TGraph::ComputeBars(Boolean redraw)
  58. {
  59.     DoGraphComputeBars(fData);
  60.     if (redraw)
  61.         ForceRedraw();
  62. }
  63.  
  64. //--------------------------------------------------------------------------------------------------
  65. #pragma segment ARes
  66.  
  67. pascal void 
  68. TGraph::GetCoordinateRange(Rect *coordRange)
  69. {
  70.     coordRange->top = DoGraphGetYMax(fData);
  71.     coordRange->bottom = DoGraphGetYMin(fData);
  72.     coordRange->left = 0;
  73.     coordRange->right = GetNumPoints();
  74. }
  75.  
  76. //--------------------------------------------------------------------------------------------------
  77. #pragma segment ARes
  78.  
  79. pascal void 
  80. TGraph::Draw(Rect *area)
  81. {
  82.     Rect    qdRect;
  83.     Rect    dstRect;
  84.     Rect    barRect;
  85.     short    numPoints;
  86.  
  87.     GetQDExtent(&qdRect);
  88.     
  89.     // draw Y-axis
  90.     dstRect = qdRect;
  91.     dstRect.right = dstRect.left + 1;
  92.     if (SectRect(&dstRect, area, &dstRect))
  93.         FrameRect(&dstRect);
  94.     
  95.     // draw X-axis
  96.     dstRect = qdRect;
  97.     dstRect.top = dstRect.bottom - 1;
  98.     if (SectRect(&dstRect, area, &dstRect))
  99.         FrameRect(&dstRect);
  100.     
  101.     // draw the bars
  102.     numPoints = GetNumPoints();
  103.     for (short i = 1; i <= numPoints; i++) {
  104.         DoGraphGetBar(i, &barRect.top, &barRect.left, &barRect.bottom, &barRect.right, fData);
  105.         if (SectRect(&barRect, area, &dstRect)) {
  106.             ForeColor(redColor);
  107.             PaintRect(&barRect);
  108.             ForeColor(blackColor);
  109.             FrameRect(&barRect);
  110.         }
  111.     }
  112.     
  113. }
  114.  
  115. //--------------------------------------------------------------------------------------------------
  116. #pragma segment AClose
  117.  
  118. pascal void 
  119. TGraph::Free()
  120. {
  121.     fData = DoGraphDispose(fData);
  122.     inherited::Free();
  123. }